#include "svm.h"
#include <string.h>

void trainSVM(char * nameTrainFile, char * nameModelFile, char * trainBinPath){

	// Now we have the training file, we are able to train the classifier with it
	// Calling the svm learning program
	char * systemcall;
	//char * execpath = "./bin/svm_learn ";
	//char * execpath = "bin\\svm_learn";
	systemcall = (char *)calloc( strlen(trainBinPath)
			+ strlen(" ")
			+ strlen(nameTrainFile)
			+ strlen(" ")
			+ strlen(nameModelFile)
			+1,// \0 a la fin
			4*sizeof(char));
	// "./svm_learn trainfile modelfile"
	strncpy(systemcall, trainBinPath, strlen(trainBinPath));
	strncat(systemcall, " ", strlen(" "));
	strncat(systemcall, nameTrainFile, strlen(nameTrainFile));
	strncat(systemcall, " ", strlen(" "));
	strncat(systemcall, nameModelFile, strlen(nameModelFile));
	printf("systemcall %s\n",systemcall);
	system(systemcall);
	free(systemcall);
}


void testSVM(char * nameTestFile, char * nameModelFile, char * nameOutputFile, char * testBinPath){

	// Now we have the training file, we are able to train the classifier with it
	// Calling the svm learning program
	char * systemcall;
	//char * execpath = "./bin/svm_learn ";
	//char * execpath = "bin\\svm_learn";
	systemcall = (char *)calloc( strlen(testBinPath)+1
			+ strlen(" ")
			+ strlen(nameTestFile)
			+ strlen(" ")
			+ strlen(nameModelFile)
			+ strlen(" ")
			+ strlen(nameOutputFile)
			+1, // \0 à la fin
			4*sizeof(char));
	// "./svm_learn trainfile modelfile"
	strncpy(systemcall, testBinPath, strlen(testBinPath));
	strncat(systemcall, " ", strlen(" "));
	strncat(systemcall, nameTestFile, strlen(nameTestFile));
	strncat(systemcall, " ", strlen(" "));
	strncat(systemcall, nameModelFile, strlen(nameModelFile));
	strncat(systemcall, " ", strlen(" "));
	strncat(systemcall, nameOutputFile, strlen(nameOutputFile));
	printf("systemcall %s\n",systemcall);
	system(systemcall);
	free(systemcall);
}
